package com.ymttest.business.service.YMTTrading;

import java.math.BigDecimal;
import java.util.Arrays;

import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFeeTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFreightTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.optrade.parameter.vo.OrderGroupVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderVo;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymttest.utils.EnvSetup;

public class TradingPlaceAuthenticateCallService {

	private static Long sellerId = Long.valueOf(EnvSetup
			.getData("autotest_seller1"));
	private static String sellerName = String.valueOf(EnvSetup
			.getData("autotest_sellerName1"));

	/**
	 * 带鉴别费订单
	 * 
	 * @param authenticateFreightType
	 * @param authenticateFreight
	 * @param authenticateFeeType
	 * @param AuthenticateFee
	 * @return
	 */
	public static TradingServiceResp placeOrderWithAuthenticate(
			AuthenticateFreightTypeEnum authenticateFreightType,
			BigDecimal authenticateFreight,
			AuthenticateFeeTypeEnum authenticateFeeType,
			BigDecimal authenticateFee) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderItemVo.setProductNum(orderItemVo.getProductNum() + 1);
		orderItemVo.withAuthenticateFee(authenticateFee)
				.withAuthenticateFeeType(authenticateFeeType.getCode())
				.withAuthenticateFlag(true);

		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderVo.withAuthenticateFreight(authenticateFreight)
				.withAuthenticateFreightType(authenticateFreightType.getCode());

		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 一个订单两个鉴别商品
	 * 
	 * @param authenticateFreightType
	 * @param authenticateFreight
	 * @param authenticateFeeTypeEnum
	 * @param AuthenticateFee
	 * @return
	 */
	public static TradingServiceResp placeOrderWithAuthenticateWithTwoProduct(
			AuthenticateFreightTypeEnum authenticateFreightType,
			BigDecimal authenticateFreight,
			AuthenticateFeeTypeEnum authenticateFeeType,
			BigDecimal authenticateFee) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderVo.withAuthenticateFreight(authenticateFreight)
				.withAuthenticateFreightType(authenticateFreightType.getCode());

		orderItemVo.withAuthenticateFee(authenticateFee)
				.withAuthenticateFeeType(authenticateFeeType.getCode())
				.withAuthenticateFlag(true);
		orderItemVo.setProductNum(orderItemVo.getProductNum() + 1);

		// 创建第二个商品
		TradingProductVo pro = TradingProductVo.createPro(sellerId, sellerName,
				100);

		OrderItemVo orderItemVo_order1_2 = TradingCallService
				.createOrderItemVo(pro.getProductId(), pro.getCatalogId());

		orderItemVo_order1_2.withAuthenticateFee(authenticateFee)
				.withAuthenticateFeeType(authenticateFeeType.getCode())
				.withAuthenticateFlag(true);

		orderVo.setOrderItems(Arrays.asList(orderItemVo, orderItemVo_order1_2));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 买家鉴定费商品、买手鉴定费商品、普通商品一起下单
	 */
	public static TradingServiceResp placeOrderWithAuthenticateWithThreeTypeProduct() {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		// 买手鉴定费商品
		orderItemVo.setProductNum(orderItemVo.getProductNum() + 1);
		orderItemVo
				.withAuthenticateFee(BigDecimal.TEN)
				.withAuthenticateFeeType(
						AuthenticateFeeTypeEnum.SELLER.getCode())
				.withAuthenticateFlag(true);

		// 买手鉴定运费
		orderVo.withAuthenticateFreight(BigDecimal.ONE)
				.withAuthenticateFreightType(
						AuthenticateFreightTypeEnum.SELLER.getCode());

		// 买家鉴定费商品
		TradingProductVo pro = TradingProductVo.createPro(sellerId, sellerName,
				100);

		OrderItemVo orderItemVo_order1_2 = TradingCallService
				.createOrderItemVo(pro.getProductId(), pro.getCatalogId());

		orderItemVo_order1_2
				.withAuthenticateFlag(true)
				.withAuthenticateFee(BigDecimal.TEN)
				.withAuthenticateFeeType(
						AuthenticateFreightTypeEnum.BUYER.getCode());

		// 普通商品
		pro = TradingProductVo.createPro(placeOrderReq.getOrderGroups().get(0)
				.getSellerId(), "sellerName", 100);

		OrderItemVo orderItemVo_order1_3 = TradingCallService
				.createOrderItemVo(pro.getProductId(), pro.getCatalogId());

		orderVo.setOrderItems(Arrays.asList(orderItemVo, orderItemVo_order1_2,
				orderItemVo_order1_3));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 鉴定费和普通商品一起下单
	 */
	public static TradingServiceResp placeOrderWithAuthenticateWithTwoTypeProduct(
			AuthenticateFreightTypeEnum authenticateFreightType,
			BigDecimal authenticateFreight,
			AuthenticateFeeTypeEnum authenticateFeeType,
			BigDecimal authenticateFee) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderItemVo.setProductNum(orderItemVo.getProductNum() + 1);
		orderItemVo.withAuthenticateFlag(true)
				.withAuthenticateFee(authenticateFee)
				.withAuthenticateFeeType(authenticateFeeType.getCode());

		// 鉴定费商品
		orderVo.withAuthenticateFreight(authenticateFreight)
				.withAuthenticateFreightType(authenticateFreightType.getCode());

		// 普通商品
		TradingProductVo pro = TradingProductVo.createPro(sellerId, sellerName,
				100);

		OrderItemVo orderItemVo_order1_2 = TradingCallService
				.createOrderItemVo(pro.getProductId(), pro.getCatalogId());

		orderVo.setOrderItems(Arrays.asList(orderItemVo, orderItemVo_order1_2));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 官方物流的鉴别订单
	 * 
	 * @param authenticateFreightType
	 * @param authenticateFreight
	 * @param authenticateFeeTypeEnum
	 * @param AuthenticateFee
	 * @return
	 */
	public static TradingServiceResp placeOrderWithAuthenticateAndOfficialLogistics(
			AuthenticateFreightTypeEnum authenticateFreightType,
			BigDecimal authenticateFreight,
			AuthenticateFeeTypeEnum authenticateFeeType,
			BigDecimal authenticateFee) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderItemVo.withAuthenticateFlag(true)
				.withAuthenticateFee(authenticateFee)
				.withAuthenticateFeeType(authenticateFeeType.getCode());
		orderItemVo.setProductNum(orderItemVo.getProductNum() + 1);

		orderVo.withAuthenticateFreight(authenticateFreight)
				.withAuthenticateFreightType(authenticateFreightType.getCode())
				.withLogisticsAging(15).withOfficialLogistics(true);

		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 根据物流类型下鉴别运费订单
	 * 
	 * @param authenticateFreightType
	 * @param authenticateFreight
	 * @param authenticateFeeType
	 * @param authenticateFee
	 * @param logisticsType
	 * @return
	 */
	public static TradingServiceResp placeOrderWithAuthenticateAndLogisticsType(
			AuthenticateFreightTypeEnum authenticateFreightType,
			BigDecimal authenticateFreight,
			AuthenticateFeeTypeEnum authenticateFeeType,
			BigDecimal authenticateFee, LogisticsTypeEnum logisticsType) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderItemVo.withAuthenticateFlag(true)
				.withAuthenticateFeeType(authenticateFeeType.getCode())
				.withAuthenticateFee(authenticateFee);
		orderItemVo.setProductNum(orderItemVo.getProductNum() + 1);

		orderVo.withLogisticsType(logisticsType)
				.withAuthenticateFreight(authenticateFreight)
				.withAuthenticateFreightType(authenticateFreightType.getCode());

		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	public static void main(String[] args) {
		TradingPlaceAuthenticateCallService
				.placeOrderWithAuthenticateAndOfficialLogistics(
						AuthenticateFreightTypeEnum.SELLER, BigDecimal.ONE,
						AuthenticateFeeTypeEnum.SELLER, BigDecimal.TEN);
	}
}
